import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


/* GridBagLayout can precisely position components, but we do not 
 * need such a detailed way. Meybe later we need.
 * 
 */

/*
public class HelloWorldSwing extends JFrame {
	public static void main(String args[])
	{
	    HelloWorldSwing app = new HelloWorldSwing();
	}
	public HelloWorldSwing()
	{
		super("James Smith's Java");
		setup();
		pack();
		show();
	}
	public void setup()
	{
		Font dataFont = new Font("courier new",Font.PLAIN,12);
		Font titleFont = new Font("courier new",Font.BOLD,14);
		Font titleFont1 = new Font("courier new",Font.BOLD,12);

		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;

		Container contentPane = getContentPane();
		contentPane.setLayout(gridbag);

		JPanel jpanel1 = new JPanel();
		jpanel1 = new JPanel()
		{
			public Dimension getPreferredSize()
			{
				Dimension size = super.getPreferredSize();
				size.width = 700;
				size.height = 100;
				return size;
			}
		};
		jpanel1.setBorder
		(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
										  "Video CD Database Application"));
		jpanel1.setLayout(gridbag);   

		// Row 1 Components -------------------------------------------
		JLabel jlabel1 = new JLabel(" Movie Database  ");
		jlabel1.setFont(titleFont);
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5; //Makes Component Spread Wider
		c.gridwidth = 1; //1 columns wide
		c.gridx = 2;	 //3rd Col  -- Very Important
		c.gridy = 0;	 //0th Row  -- Very Important
		gridbag.setConstraints(jlabel1, c);
		jpanel1.add(jlabel1);

		// Row 2 Components -------------------------------------------
		JLabel jlabel2 = new JLabel(" Title : ");
		jlabel2.setFont(titleFont1);
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 0;
		c.gridy = 1;
		gridbag.setConstraints(jlabel2, c);
		jpanel1.add(jlabel2);

		JLabel jlabel3 = new JLabel(" Marrying Rich Men ");
		jlabel3.setFont(dataFont);
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 1;
		c.gridy = 1;
		gridbag.setConstraints(jlabel3, c);
		jpanel1.add(jlabel3); 

		JLabel jlabel4 = new JLabel(" Sl No : ");
		jlabel4.setFont(titleFont1);
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 2;
		c.gridy = 1;
		gridbag.setConstraints(jlabel4, c);
		jpanel1.add(jlabel4); 

		JLabel jlabel5 = new JLabel(" 12 ");
		jlabel5.setFont(dataFont);
		c.fill = GridBagConstraints.WEST;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 3;
		c.gridy = 1;
		c.insets = new Insets(0,0,0,20);  //(top.left,bottom,right) Padding
		gridbag.setConstraints(jlabel5, c);
		jpanel1.add(jlabel5);

		JButton buttonF = new JButton(new ImageIcon("first.gif"));
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 4;
		c.gridy = 1;
		c.insets = new Insets(0,0,0,0);
		gridbag.setConstraints(buttonF, c);
		jpanel1.add(buttonF); 

		JButton buttonP = new JButton(new ImageIcon("back.gif"));
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 5;
		c.gridy = 1;
		gridbag.setConstraints(buttonP, c);
		jpanel1.add(buttonP);

		JButton buttonN = new JButton(new ImageIcon("next.gif"));
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 6;
		c.gridy = 1;
		gridbag.setConstraints(buttonN, c);
		jpanel1.add(buttonN);

		JButton buttonL = new JButton(new ImageIcon("last.gif"));
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 7;
		c.gridy = 1;
		gridbag.setConstraints(buttonL, c);
		jpanel1.add(buttonL);     

		//Row 3 Components -----------------------------------------
		JLabel jlabel6 = new JLabel(" Star : ");
		jlabel6.setFont(titleFont1);
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 0;
		c.gridy = 2;
		gridbag.setConstraints(jlabel6, c);
		jpanel1.add(jlabel6); 

		JLabel jlabel7 = new JLabel(" Anna Nicole Smith ");
		jlabel7.setFont(dataFont);
		c.fill = GridBagConstraints.BOTH;
		c.ipady = 1;
		c.ipadx = 1;
		c.gridx = 1;
		c.gridy = 2;
		gridbag.setConstraints(jlabel7, c);
		jpanel1.add(jlabel7); 

		addWindowListener(new WindowEventHandler());
		contentPane.add(jpanel1);
	}

	class WindowEventHandler extends WindowAdapter {
		public void windowClosing(WindowEvent e)
		{
			System.exit(0);
		}
	}
}
*/


/*
Stage 4: Adding 2 More Panels which holds Radio Button and Check Boxes 
We are at a crutial Point what we will do now is, so concentrate more on Panel2 and Panel3
 1) Resize the First Pane we created
 2) Add One more pane to Hold CheckBoxes
 3) Add One more pane to Hold Radiobutton belonging to same Button Group
 4) getPreferredSize() is responsible for the Size of Individual Panel height and width
 5) ButtonGroup() is responsible for all 3 buttons belonging to same family, so only one gets selected at a time 
*/


//Requirements and Imports HelloWorldSwing.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class HelloWorldSwing extends JFrame 
{
    //Main starts the Application and Initialises the Constructor
    public static void main(String args[])
    {
	HelloWorldSwing app = new HelloWorldSwing();
    }
    
    //Constructor Defines the Frame Title and calls Setup Method
    public HelloWorldSwing()
    {
	super("My Simple Application");
	setup();
	pack();
	show();
    }
    //Setup Method is responsible for Creating Panel, Defining Size, adding Componets to the Panel
    public void setup()
    {
	Container contentPane = getContentPane();
	contentPane.setLayout(new FlowLayout());

	//Panel 1 Start -------------------------------------------
	JPanel jpanel1 = new JPanel()
	{
	    public Dimension getPreferredSize()
	    {
		Dimension size = super.getPreferredSize();
		size.width = 250;
		size.height = 150;
		return size;
	    }
	};
	
	jpanel1.setBorder
	(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Border 1"));
	JLabel label1 = new JLabel("My Label");
	jpanel1.add(label1);
	JTextField textbox1 = new JTextField("My TextBox",15);
	jpanel1.add(textbox1);
	JLabel label2 = new JLabel(new ImageIcon("think.gif"));
	jpanel1.add(label2);
	contentPane.add(jpanel1);

	//Panel 2 Start -------------------------------------------
	JPanel jpanel2 = new JPanel()
	{
	    public Dimension getPreferredSize()
	    {
		Dimension size = super.getPreferredSize();
		size.width = 150;
		size.height = 150;
		return size;
	    }
	};
	jpanel2.setBorder
	(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Border 2"));
	JCheckBox checkbox1 = new JCheckBox("Check Box1");
	jpanel2.add(checkbox1);
	JCheckBox checkbox2 = new JCheckBox("Check Box2");
	checkbox2.setSelected(false);
	jpanel2.add(checkbox2);
	JCheckBox checkbox3 = new JCheckBox("Check Box3");
	checkbox3.setSelected(true);
	jpanel2.add(checkbox3);
	JButton button1 = new JButton("My Button");
	jpanel1.add(button1);
	contentPane.add(jpanel2);

	//Panel 3 Start -------------------------------------------
	ButtonGroup bg = new ButtonGroup();
	JPanel jpanel3 = new JPanel()
	{
	    public Dimension getPreferredSize()
	    {
		Dimension size = super.getPreferredSize();
		size.width = 150;
		size.height = 150;
		return size;
	    }
	};
	jpanel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Border 3"));
	JRadioButton radio1 = new JRadioButton("Radio Button1",true);
	jpanel3.add(radio1);
	bg.add(radio1);
	JRadioButton radio2 = new JRadioButton("Radio Button2",false);
	jpanel3.add(radio2);
	bg.add(radio2);
	JRadioButton radio3 = new JRadioButton("Radio Button3",false);
	jpanel3.add(radio3);
	bg.add(radio3);
	contentPane.add(jpanel3);

	addWindowListener(new WindowEventHandler());
    }
    //WindowEventHandler is responside for Closing the Application when close is clicked
    class WindowEventHandler extends WindowAdapter 
    {
	public void windowClosing(WindowEvent e)
	{
	    System.exit(0);
	}
    }
}


/*
//Stage 3: setting Borders, Displaying Image
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class HelloWorldSwing extends JFrame {
	//Main starts the Application and Initialises the Constructor
	public static void main(String args[])
	{
		HelloWorldSwing app = new HelloWorldSwing();
	}
	//Constructor Defines the Frame Title and calls Setup Method
	public HelloWorldSwing()
	{
		super("My Simple Application");
		setup();
		pack();
		show();
	}
	//Setup Method is responsible for Creating Panel, Defining Size, adding Componets to the Panel
	public void setup()
	{
		Container contentPane = getContentPane();
		contentPane.setLayout(new FlowLayout());
		JPanel jpanel1 = new JPanel();
		jpanel1 = new JPanel()
		{
			public Dimension getPreferredSize()
			{
				Dimension size = super.getPreferredSize();
				size.width = 300;
				size.height = 100;
				return size;
			}
		};
		jpanel1.setBorder
		(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"My Border 1"));
		JLabel label1 = new JLabel("My Label");
		jpanel1.add(label1);
		JTextField textbox1 = new JTextField("My TextBox",15);
		jpanel1.add(textbox1);
		JLabel label2 = new JLabel(new ImageIcon("think.gif"));
		jpanel1.add(label2);
		contentPane.add(jpanel1);

		addWindowListener(new WindowEventHandler()); 

	}
	//WindowEventHandler is responside for Closing the Application when close is clicked
	class WindowEventHandler extends WindowAdapter {
		public void windowClosing(WindowEvent e)
		{
			System.exit(0);
		}
	}
}
*/


/* Stage 2: Requirements and Imports HelloWorldSwing.java
 * Requirements Are :
 1) Min, Max, Close Button
 2) Display Application Title, Set Height and Width of the Application
 3) a Container which holds many panels and panel which can hold many components such as Label and TextBox
 4) Close the Application when close Button is Clicked
 5) Flowlayout is easiest layout like wriing on a paper top right to topleft and after that start in new line
 */
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class HelloWorldSwing extends JFrame {
	//Main starts the Application and Initialises the Constructor
	public static void main(String args[])
	{
		HelloWorldSwing app = new HelloWorldSwing();
	}
	//Constructor Defines the Frame Title and calls Setup Method
	public HelloWorldSwing()
	{
		super("My Simple Application");
		setup();
		pack();
		show();
	}
	//Setup Method is responsible for Creating Panel, Defining Size, adding Componets to the Panel
	public void setup()
	{
		Container contentPane = getContentPane();
		contentPane.setLayout(new FlowLayout());
		JPanel jpanel1 = new JPanel();
		jpanel1 = new JPanel()
		{
			public Dimension getPreferredSize()
			{
				Dimension size = super.getPreferredSize();
				size.width = 300;
				size.height = 100;
				return size;
			}
		};
		JLabel label1 = new JLabel("My Label");
		jpanel1.add(label1);
		JTextField textbox1 = new JTextField("My TextBox",15);
		jpanel1.add(textbox1);
		contentPane.add(jpanel1);
		addWindowListener(new WindowEventHandler());

	}
	//WindowEventHandler is responside for Closing the Application when close is clicked
	class WindowEventHandler extends WindowAdapter {
		public void windowClosing(WindowEvent e)
		{
			System.exit(0);
		}
	}
}
*/


/* Stage 1
import javax.swing.*;        

public class HelloWorldSwing
{
    public static void main(String[] args)
    {
        JFrame frame = new JFrame("HelloWorldSwing");
        
        final JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
*/